/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jobscheduling.model;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import jobscheduling.gui.GUI;

/**
 *
 * @author Dawid
 */
public class Output {
    private static Output _instance = new Output();
    private Output () {}
    
    protected Map<Problem, List<Solution>> _results = new TreeMap<Problem, List<Solution>>();
    protected List<Problem> _problems = new LinkedList<Problem>();
    
    public static Output getInstance(){
        return _instance;
    }
    
    public synchronized List<Problem> getProblems(){
        return _problems;
    }
    
    public synchronized List<Solution> getSolutions(Problem problem){
        return _results.get(problem);
    }
    
    public synchronized void removeProblem(Problem problem){
        _problems.remove(problem);
        _results.remove(problem);
    }
    
    public synchronized void removeSolution(Solution solution, Problem problem){
        List<Solution> get = _results.get(problem);
        if (problem != null){
            get.remove(solution);
        }
    }
    
    public synchronized void addSolutions (List<Solution> solutions){
        for (Solution solution : solutions){
            Problem problem = solution.getProblem();
            if (_problems.contains(problem) == false){
                _problems.add(problem);
            }
            List<Solution> list = _results.get(problem);
            if (list == null)
                list = new LinkedList<Solution>();
            list.add(solution);
            _results.put(solution.getProblem(), list);
        }
        GUI.getInstance().refreshInputList();
    }
}
